package com.lkd.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ser.Serializers;
import com.lkd.base.BaseController;
import com.lkd.base.ResponseResult;
import com.lkd.domain.Sku;
import com.lkd.pageParam.SkuPageParam;
import com.lkd.service.ISkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-02-08
 */
@RestController
@Api("商品接口")
@RequestMapping("/api/vm-service/sku")
public class SkuController extends BaseController {
    @Autowired
    private ISkuService skuService;

    @ApiOperation("新增商品")
    @PostMapping
    public ResponseResult addSku(@RequestBody Sku sku){
        skuService.save(sku);
        return success();
    }
    @ApiOperation("商品搜索")
    @GetMapping
    public ResponseResult<Page<Sku>> search(SkuPageParam param){
        Page<Sku> page =  skuService.getPage(param);
        return success(page);
    }
    @ApiOperation("修改商品")
    @PutMapping
    public ResponseResult update(@RequestBody Sku sku){
        skuService.updateById(sku);
        return success();
    }
    @ApiOperation("根据商品id删除商品")
    @PutMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        skuService.removeById(id);
        return success();
    }
    @ApiOperation("获取所有商品列表")
    @GetMapping("/all")
    public ResponseResult<List<Sku>> getAll(){
        List<Sku> list = skuService.list();
        return success(list);
    }
}
